package com.softstao.guoyu.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.softstao.guoyu.R;
import com.softstao.softstaolibrary.library.utils.LZUtils;

/**
 * Created by vaikus on 2017/6/14.
 */

public class HintDialog extends Dialog {
    private Context mContext;
    private ImageView icon;
    private TextView title;
    private TextView content;
    private TextView cancel;
    private TextView confirm;
    private ImageView cancelIc;
    public HintDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public HintDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    protected HintDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    private void initView(Context context){
        mContext = context;
        setContentView(R.layout.layout_hint_dialog);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        cancelIc = (ImageView) findViewById(R.id.cancel_ic);
        icon = (ImageView) findViewById(R.id.hint_ic);
        title = (TextView) findViewById(R.id.hint_title);
        content = (TextView) findViewById(R.id.hint_content);
        content.setVisibility(View.GONE);
        cancel = (TextView) findViewById(R.id.cancel_btn);
        cancel.setVisibility(View.GONE);
        confirm = (TextView) findViewById(R.id.confirm_btn);
        cancelIc.setOnClickListener(v -> onCancel());
        cancel.setOnClickListener(v -> onCancel());
    }

    public void onCancel()
    {
        dismiss();
    }

    public void setIcon(int iconResource){
        icon.setImageResource(iconResource);
    }

    public void setTitle(String text) {
        title.setText(text);
    }

    public void setContent(String text) {
        content.setText(text);
    }

    public void setConfirm(String text) {
        confirm.setText(text);
    }

    public void setCancelVisible() {
        cancel.setVisibility(View.VISIBLE);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(getWindow().getAttributes().width/2-60, LZUtils.dipToPix(mContext, 35));
        params.setMargins(30,0,30,0);
        cancel.setLayoutParams(params);
        confirm.setLayoutParams(params);
    }

    public void setContentVisible(){
        content.setVisibility(View.VISIBLE);
    }

    public ImageView getIcon() {
        return icon;
    }

    public TextView getTitle() {
        return title;
    }

    public TextView getContent() {
        return content;
    }

    public TextView getCancel() {
        return cancel;
    }

    public TextView getConfirm() {
        return confirm;
    }

    public ImageView getCancelIc() {
        return cancelIc;
    }
}
